package com.counterapp.tutorial.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.counterapp.tutorial.model.bean.ClassroomService;

@Controller
@RequestMapping(value = { ClassroomController.URL_MAPPING, "/" })
public class ClassroomController {
	public static final String URL_MAPPING = "/classroom";
	public static final String VIEW_NAME = "classroom";

	public static final Logger LOGGER = LoggerFactory.getLogger(ClassroomController.class);

	private ClassroomService classroomService = new ClassroomService();

	@Autowired
	public ClassroomController(ClassroomService classroomService) {
		this.classroomService = classroomService;
	}

	@RequestMapping(method = RequestMethod.GET)
	public String handleRequest(ModelMap map) throws Exception {
		return VIEW_NAME;
	}

	@RequestMapping(value = "/classroom/{classroomId}", method = RequestMethod.GET)
	public String getClassroom(@PathVariable("classroomId") Long classroomId, ModelMap modelMap) {
		LOGGER.info("Adquirido o seguinte ID: " + classroomId);
		
		modelMap.addAttribute("classroom", classroomService.getClassroomService(classroomId));

		return VIEW_NAME;
	}

}
